#include<iostream>
using std::endl;
using std::cout;

class Point{

public:
    //申请在堆上
    static Point* getInstance(){
        //错了 因为地址不同
        if(pre == nullptr){
            pre = new Point();
        }
        return pre;
    }
    void Init(int x,int y){
        _x = x;
        _y = y;
    }
    void printPoint(){
        cout<<_x<<endl;
        cout<<_y<<endl;
    }
    void destory(){
        if(pre != nullptr){
            cout<<"~destory"<<endl;
            delete pre;
            pre = nullptr;
        }
    }
private:
    Point(){};
    Point(const Point&rhs) = delete;
    Point&operator=(const Point&rhs) = delete;
    Point(int x,int y)
    :_x(x)
    ,_y(y)
    {}


private:
    int _x;
    int _y;
    static Point* pre;
};
Point* Point::pre = nullptr;

int main(void){
    Point *pre1 = Point::getInstance();
    Point *pre2 = Point::getInstance();
    printf("%p\n",pre1);
    printf("%p\n",pre2);
    pre1->Init(100,300);
    pre1->printPoint();
    pre2->Init(200,400);
    pre1->printPoint();
    pre1->destory();
    pre2->destory();
}